package com.generator.config;

import java.util.HashMap;
import java.util.Map;

import com.generator.tools.text.StringUtils;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class ContextConfig {
	private String author;
	
	private String driverClassName;
	private String url;
	private String user;
	private String password;
	private String db;
	private String tableEntityMappings;
	private String basePackage;
	private String codeDirPath;
	private String projectName;
	private String codePath;
	private String mapperPath;
	
	private boolean modelFlag;
	private boolean mapperFlag;
	private boolean mapperXmlFlag;
	private boolean serviceFlag;
	private boolean serviceImplFlag;
	private boolean controlFlag;
	
	public  Map<String,String> popularTableEntityMappingsToMap(){
		if(!StringUtils.isEmpty(tableEntityMappings)) {
			Map<String,String> map=new HashMap<String, String>();
			String[] array = tableEntityMappings.split(",");
			for (String str : array) {
				if(!StringUtils.isEmpty(str)) {
					String[] kv = str.split("#");
					if(!StringUtils.isEmpty(kv[0])&&
							!StringUtils.isEmpty(kv[1])
							&&
							kv.length==2) {
						map.put(kv[0], kv[1]);
					}
				}
			}
			return map;
		}
		return null;
	}
}
